<template>
  <div class="card" style="max-width:520px;margin:40px auto;padding:20px;">
    <h2 style="margin-top:0;">注册</h2>
    <form class="space-y" @submit.prevent="submit">
      <div class="space-y">
        <label class="muted">用户名</label>
        <input class="input" v-model="username" required />
      </div>
      <div class="space-y">
        <label class="muted">邮箱</label>
        <input class="input" type="email" v-model="email" required />
      </div>
      <div class="space-y">
        <label class="muted">电话</label>
        <input class="input" v-model="phone" required />
      </div>
      <div class="space-y">
        <label class="muted">密码</label>
        <input class="input" type="password" v-model="password" required />
      </div>
      <button class="btn" type="submit">注册</button>
    </form>
  </div>
</template>

<script>
export default {
  data(){ return { username:'', email:'', phone:'', password:'' } },
  methods:{
    async submit(){
      const res = await fetch('/api/v1/auth/register', { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({ username:this.username, email:this.email, phone:this.phone, password:this.password }) })
      if(res.ok){
        alert('注册成功，请登录')
        location.hash = '#/login'
      }
    }
  }
}
</script>


